/**
 * 
 */
package com.phone580.app.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.phone580.app.db.AppHelperDatabase.DatabaseHelper;



/**
 * @author xianpunan
 * @date     2012-4-12
 */
public abstract class AppHelperDBManager {
	
	protected Context mContext;

	private DatabaseHelper mDatabaseHelper;

	protected static SQLiteDatabase mSQLiteDatabase;
	
	public AppHelperDBManager(Context context) {
		this.mContext = context;
	}
	
	protected void open() {
		if (mSQLiteDatabase  == null || !mSQLiteDatabase.isOpen()) {
			mDatabaseHelper = new DatabaseHelper(mContext);
			mSQLiteDatabase = mDatabaseHelper.getWritableDatabase();
		}
	}
	
	public void close() {
		if (mSQLiteDatabase == null || !mSQLiteDatabase.isOpen()) {
			mDatabaseHelper.close();
			mDatabaseHelper = null;
		}
	}

	public static SQLiteDatabase getSqLiteDatabase(Context context) {
		DatabaseHelper databaseHelper = new DatabaseHelper(context);
		SQLiteDatabase sqliteDatabase = databaseHelper.getWritableDatabase();
		return sqliteDatabase;
	}
	
}
